﻿using UnityEngine;

namespace NpcFramework
{
    public class NpcViewLayerManager
    {
        private NpcViewLayer npcViewLayer;


        public void Dispose()
        {
            npcViewLayer?.Dispose();
            npcViewLayer = null;
        }

        public void SwitchViewLayer(NpcViewLayer viewLayer)
        {
            this.npcViewLayer = viewLayer;
        }
        
        private T GetInterface<T>() where T : class
        {
            if (npcViewLayer == null || !npcViewLayer.Enable)
            {
                return null;
            }

            return (npcViewLayer as T);
        }

        // 设置位置、旋转
        public void SetPosition(int npcId, Vector3 pos)
        {
            if (npcViewLayer!=null && npcViewLayer.Enable) npcViewLayer.SetPosition(npcId, pos);
        }
        
        public void SetRotation(int npcId, Quaternion rot)
        {
            if (npcViewLayer!=null && npcViewLayer.Enable) npcViewLayer.SetRotation(npcId, rot);
        }
        
        // 播放动画
        public void PlayAnimation(int npcId, string stateName, int layer = -1, float normalizedTime = float.NegativeInfinity)
        {
            GetInterface<INpcAnimation>()?.PlayAnimation(npcId,stateName,layer,normalizedTime);
        }


        // 播放特效
        
        
        // ...

    }
}
